<template>
    <div class="qrcode-wrapper">
        <centerHeader/>

        <div class="qrcode-wrap">
            <div class="top-wrap">
                <div class="title_box">
                    <span class="title-01">我的顾客</span>
                    <i class="el-icon-arrow-down"></i>
                </div>
            </div>
            <div class="commission">

                <div class="comm_top clearfix">
                    <div class="fl">
                        <span>{{item.username}}</span>
                        <span>{{item.sex}}</span>
                    </div>
                    <div class="fr">
                        <i class="el-icon-phone"></i>
                        {{item.mobile}}
                    </div>
                </div>
                <div class="comm_middle">
                    <i class="el-icon-time"></i> {{item.regedit_time | formatTime}}
                </div>
                <div class="comm_bottom comm_clerk ">
                    <div >
                        <i class="el-icon-time"></i>
                       {{item.store_user.username}}
                        <el-button size="mini" round class="clerk_color">店员</el-button>
                    </div>
                    <div >
                        <el-button size="mini" round class="fr reform_clerk" @click="allot">重新分配店员</el-button>
                    </div>

                </div>
            </div>

            <transition name="slide-fade" class="tran_box">
                <div class="hotKey-wrap" v-if="isCustomer">
                    <div class="shop_detail">
                        <i class="el-icon-close shop_close" @click="close"></i>
                        <div class="add_clerk1">
                            <div class="order_sn">订单号:{{orderitem.order_sn}}</div>
                            <div class="order_box">
                                <div class="order_top">
                                    <img :src="orderitem.product_img" alt="">
                                    <div class="order_text">
                                        {{orderitem.product_title}}
                                    </div>
                                </div>
                                <div class="order_price">
                                    <div class="order_real">
                                        <span>共计{{orderitem.product_count}}个项目</span><span>实付款：￥{{orderitem.real_price}} 元</span>
                                    </div>
                                    <div>{{orderitem.create_time | formatTime}}</div>
                                </div>
                            </div>
                        </div>


                    </div>
                </div>
            </transition>
            <transition name="slide-fade" class="tran_box">
                <div class="hotKey-wrap" v-if="isCerlk">
                    <div class="shop_detail">
                        <i class="el-icon-close shop_close" @click="close1"></i>
                        <div class="add_clerk1">
                            <el-select v-model="uid" placeholder="请选择">
                                <el-option
                                    v-for="item in customerlist"
                                    :key="item.uid"
                                    :label="item.name"
                                    :value="item.uid">
                                </el-option>
                            </el-select>
                        </div>
                        <div class="submit-box">
                            <button class="submit-btn" @click="save">保存</button>
                        </div>

                    </div>
                </div>
            </transition>
        </div>
        <div class="commission">
            <div class="com_title">
                订单信息
            </div>
            <ul class="clerk_ul" v-for="item in orderlist" :key="item.order_id">
                <li @click="get_orderDetail(item.order_id)">
                    <div class="item_top">
                        <div>订单编号:{{item.order_sn}}</div>
                    </div>
                    <div class="item_bottom">
                        <div v-if="item.order_status == 1">￥{{item.total_price}}</div>
                        <div v-else>￥{{item.real_price}}</div>
                        <div>{{item.create_time | formatTime}}</div>
                    </div>
                </li>
            </ul>
            <div class="com_title" @click="order_list">

                <i class="el-icon-plus"></i>
                加载更多
            </div>
        </div>
        <centerFooter/>
    </div>
</template>

<script type="text/ecmascript-6">
    import centerHeader from "@/views/center/components/centerHeader";
    import centerFooter from "@/views/center/components/centerFooter";
    import constant from "@/utils/constant.js";
    import { formatTime } from "@/utils/index.js";
    // 引用API文件
    import http from "@/utils/http.js";

    import QRCode from "qrcode";

    export default {
        name: "qrcode",
        data() {
            return {
                orderlist:[],
                item:{
                    username:"",
                    sex:"",
                    mobile:"",
                    regedit_time:"",
                    store_user:{
                        username:""
                    }
                },
                isCustomer:false,
                isCerlk:true,
                orderitem:{},
                user_info:{},
                customerlist:[],
                uid:""
            };
        },
        components: {
            centerHeader,
            centerFooter
        },
        methods: {
            userinfo() {
                http.get(this, {
                    url: "ucenter/user_info",
                    data: {
                        token: localStorage.getItem("user_token")
                    },
                    dataType: "json",
                    success: function(data) {
                        console.log("用户信息:", data);
                        if (data.status == 1) {
                            this.user_info = data.info;

                            // 获取页面的canva
                        } else {
                        }
                    }
                });
            },
            query_customerDetail(id){
                http.get(this, {
                    url: "uncenter/user_detail",
                    data: {
                        token: localStorage.getItem("user_token"),
                        uid:id
                    },
                    dataType: "json",
                    success: function(data) {
                        if(data.status == 1){
                            this.item = data.info;
                        }else{
                            this.$message.error(data.info);
                        }

                    }
                })
            },
            order_list() {
                let id = this.$route.query.id;
                this.p++;
                http.get(this, {
                    url: "order/order_list",
                    data: {
                        pagesize: 5,
                        p: this.p,
                        token: localStorage.getItem("user_token"),
                        uid:id
                    },
                    dataType: "json",
                    success: function(data) {
                        if (data.status == 1) {
                            let info = data.info;
                            if (this.p <= info.total_page) {
                                this.orderlist = this.orderlist.concat(info.list);
                            }
                        }
                    }
                });
            },

            close(){
              this.isCustomer = false
            },
            close1(){
                this.isCerlk = false
            },
            get_orderDetail(id){
                http.get(this, {
                    url: "order/order_detail",
                    data: {
                        order_id: id,
                        token: localStorage.getItem("user_token")
                    },
                    dataType: "json",
                    success: function(data) {
                        console.log("订单详情:", data);
                        if (data.status == 1) {
                            this.orderitem = data.info;
                        } else {
                            this.$message.error(data.info);
                        }
                    }
                });
            },
            allot(){
                http.get(this, {
                    url: "/ucenter/user_list",
                    data: {
                        token: localStorage.getItem("user_token"),
                        uid:this.user_info.uid
                    },
                    dataType: "json",
                    success: function(data) {
                        console.log(data)
                        if(data.status == 1){
                            this.customerlist = data.info.list
                            this.isCerlk = true
                        }else{
                            this.$message.error(data.info);
                        }

                    }
                })
            },
            save(){
                http.get(this, {
                    url: "/ucenter/personal",
                    data: {
                        token: localStorage.getItem("user_token"),
                        uid:this.uid,
                        store_uid:this.user_info.store_uid
                    },
                    dataType: "json",
                    success: function(data) {
                        console.log(data)
                        if(data.status == 1){
                            this.$message.error('重新分配成功');
                            this.isCerlk = false
                        }else{
                            this.$message.error(data.info);
                        }

                    }
                })
            }
        },

        created() {
            let id = this.$route.query.id;
            this.query_customerDetail(id)
            this.order_list()
            this.userinfo()
        },
        watch: {
            $route() {
                console.log("监听");
                this.orderlist = [];
                this.p = 0;
                this.order_list();
            }
        },

    };
</script>

<style scoped lang="scss">
    .qrcode-wrapper {
    }

    .top-wrap {
        $letHeight: 1.3rem;

        .title-txt {
            height: $letHeight;
            line-height: $letHeight;
            text-align: center;
            background-color: $c-white-light;

            span {
                color: $c-mainC;
                display: inline-block;
                line-height: $letHeight;
                vertical-align: middle;

                &.title-01 {
                    font-size: 0.38rem;
                }
            }
        }
    }

    .main-wrap {
        @extend .cmm-border;
    }

    .img-wrap {
        width: 5rem;
        height: 5rem;
        margin: 0.4rem auto;
        overflow: hidden;
        position: relative;
        padding: 0.22rem;

        .ad-img {
            @extend .cmm-translateXY;
            width: 100%;
        }
    }

    .qrcode-box {
        text-align: center;
        width: 100%;
        .qrcode-txt {
            width: 5.15rem;
            border-radius: 0.8rem;
            background-color: $c-danger;
            font-size: 0.52rem;
            color: $c-white-light;
            $letHeight: 0.6rem;
            height: $letHeight;
            line-height: $letHeight;
            text-align: center;
            margin: 0.48rem auto;
            display: inline-block;
            letter-spacing: 0.1rem;
            font-weight: bold;
        }
    }
    .title-txt-new{
        height:1rem;
        line-height:1rem;
        text-align: center;
        background-color: $c-white-light;
        font-size: 0.32rem;
    }
    .picker{
        padding:0 10px;
        border-top: 0.15rem solid #eeeeee;
        .el-date-editor.el-input, .el-date-editor.el-input__inner{
            width:2.2rem;
        }
        /deep/.el-input__inner{
            border: none;
        }
    }
    .shop_table_header{
        display: flex;
        line-height:1rem;
        padding:0 0.2rem;
        border-bottom:1px solid #eeeeee;
        &>div.th_one{
            flex:2
        }
        &>div.th_two{
            flex:1
        }
    }
    .shop_table_table{
        &>li{
            padding:0.25rem 0.2rem;
            display: flex;
            &>div.td_one{
                flex:2;
                &>div.td_item_one{
                    margin-bottom:0.2rem;
                }
                &>div.td_item_two{
                    &>span{
                        font-size: 0.08rem;
                    }

                }
            }
            &>div.td_two{
                flex:1;
                &>div.td_item_one{
                    margin-bottom:0.2rem;
                }
                &>div.td_item_two{
                    &>span{
                        font-size: 0.08rem;
                    }

                }
            }
        }
    }
    .title_box{
        height: 0.9rem;
        line-height:0.9rem;
        font-size: 0.36rem;
        text-align: center;
    }
    .commission{
        border-top: 0.15rem solid #eeeeee;
        font-size: 0.3rem;
        .com_box{
            height: 1rem;
            line-height:1rem;
            padding:0 0.3rem;
            border-bottom:1px solid #eeeeee;
            &>span{
                line-height:1rem;
                display: flex;
                justify-content: center;
            }
        }
    }
    .fl{
        float: left;
    }
    .fr{
        float: right;
    }
    .com_title{
        height: 1rem;
        line-height:1rem;
        text-align: center;
        font-size: 0.36rem;
        border-bottom:0.01333rem solid #eeeeee;
    }
    .com_ul{
        li{
            padding:0.25rem 0.3rem;
            border-bottom:1px solid #eeeeee;
            .com_top{
                line-height:0.5rem;
                margin-bottom:0.2rem;
            }
            .com_name{
                float: left;
            }
            .com_orderId{
                font-size: 0.2rem!important;
                float: left;
            }
            .com_price{
                font-size: 0.5rem;
                color:#ff4c4c;
                float: right;
            }
            .com_time{
                float: right;
            }
        }
    }
    .com_color{
        font-size: 0.45rem;
        color:#ff4c4c;
    }
    .com_list{
        /deep/.el-tabs__nav-wrap{
            margin:0 0.25rem;
        }
        /deep/.el-tabs__nav{
            width:100%
        }
        /deep/.el-tabs__item{
            width:25%;
            text-align: center;
            height: 1rem;
            line-height:1rem;

        }
        /deep/.el-tabs__item.is-active{
            color: #ff4c4c;
            font-weight: 500;
        }
        /deep/.el-tabs__active-bar{
            background-color:#ff4c4c;
        }
        /deep/.el-tabs__nav-wrap::after{
            background-color: #ffffff;
        }
        /deep/.el-form{
            padding:0 0.5rem;
            margin-bottom:0.6rem;
            .el-form-item{
                border-bottom:0.013333rem solid #dcdfe6;
                margin-top:0.3rem;
            }
            .el-form-item__label{
                text-align: left;
                width:1.2rem!important;
            }
            .el-form-item__content{
                margin-left:1.2rem!important;
                .el-input__inner{
                    border:none;
                }
            }
        }
    }
    .tab_ul{
        li{
            padding:0.25rem;
            border-bottom:1px solid #eeeeee;
        }
        .tab_item_top{
            margin-bottom:0.28rem;

            .tab_item_time{
                float:left;
            }
            .tab_item_type{
                float:right;
            }
        }
    }
    .tab_item_bottom{
        display: flex;
        .tab_item_order{
            flex:1;
            text-align: left;
        }
        .tab_item_cash{
            flex: 1;
            text-align: center;
        }
        .tab_item_timer{
            flex: 1.2;
            text-align: right;
        }
    }
    .comm_top,.comm_middle,.comm_bottom{
        height:1rem;
        line-height: 1rem;
        padding: 0 0.25rem;
        font-size:0.3rem;
    }
    .clerk_color{
        background-color: red;
        color:#ffffff;
    }
    .reform_clerk{
        background-color:#BC9F5B;
        color:#ffffff;
    }
    .comm_clerk{
        display: flex;
        align-items: center;
        &>div{
            flex:1;
        }
        &>div:last-child{
            text-align: right;
        }
    }
    .clerk_ul{
        li{
            display: flex;
            padding:0.25rem;
            font-size: 0.25rem!important;
            border-bottom:0.0133rem solid #eeeeee;
            &>.item_top{
                flex:3;
                display: flex;
                align-items: center;
            }
            &>.item_bottom{
                flex:2;
                &>div:first-child{
                    margin-bottom:0.2rem;
                }
            }
        }
    }
    .add_clerk{
        padding-top:0.8rem;
        .title{
            font-size: 0.3rem;
            margin-bottom: 0.6rem;
            margin-left:0.2rem;
        }
        /deep/.el-input__inner{
            border-top:none;
            border-left:none;
            border-right:none;

        }
    }
    /deep/.el-form-item{
        margin-bottom:0.4rem;
    }
    /deep/.el-form-item__label{
        text-align: center;
    }
    .add_clerk1{
        padding:0.8rem 0.25rem 0 0.25rem;
        font-size: 0.24rem;
        text-align: center;
        border-bottom:0.01333rem solid #eeeeee;
        &>div{
            margin-bottom:0.25rem;
        }
    }
    .custom_box{
        .custom_title{
            height:1rem;
            line-height: 1rem;
            text-align: center;
            font-size: 0.3rem;
        }
        .custom_ul{
            li{
                width:25%;
                float:left;
                margin-bottom:0.2rem;
                &>a{
                    margin:0 0.1rem;
                    background-color: #eeeeee;
                    display:block;
                    line-height: 0.6rem;
                    text-align: center;
                }
            }
        }
    }
    .shop_close{
        position: absolute;
        right: 0.3rem;
        top:0.32rem;
        font-size: 0.32rem;
    }
    .shop_detail{
        position: relative;
    }
    .order_top{
        position: relative;
        &>img{
            position: absolute;
            top:0;
            left:0;
            width:2rem;
            height:1rem;
            border:1px solid #eeeeee;
            display: block;
        }
        &>.order_text{
            margin-left:2.2rem;
            min-height: 1rem;
            white-space: normal;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    }
    .order_sn{
        margin-bottom:0.3rem;
    }
    .order_price{
        text-align: right;
        margin-top:0.3rem;
    }
    .order_real{
        margin-bottom:0.2rem;
    }
    .submit-box{
        padding:0 0.25rem;
    }
</style>
